<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <home></home>
  </div>
  <script src="./vue.js"></script>
  <script>

    const Home = {
      template: `
        <div>
          <h2>这是一个组件</h2>  
          <ul ref='oul'>
            <li v-for="item in cates" :key="item">
              {{item}}  
            </li>  
          </ul>
        </div>
      `,
      data() {
        return {
          // 1现在data中定义初始值
          cates: []
        }
      },
      created(){
        // 3 created调用封装好的请求函数
        this.fetchItems();
      },
      methods: {
        fetchItems() {
          //  2调用ajax请求函数
          setTimeout(() => {
            const cates = [1,2,3,4,5];
            this.cates = cates;
          }, 2000)
        }
      }
    }

    Vue.component('Home', Home)
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      }
    })
  </script>
</body>

</html>